package com.itheima.service.serviceimpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.dao.CheckItemDao;
import com.itheima.pojo.CheckItem;
import com.itheima.service.InspectionItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InspectionItemsServiceImpl implements InspectionItemsService {

    @Autowired
    private CheckItemDao inspectionItemsMapper;
    @Override
    public List<CheckItem> findAll() {
        List<CheckItem> checkItems = inspectionItemsMapper.findAll();
        return checkItems;
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        PageHelper pageHelper = new PageHelper();
        pageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());

        Page<CheckItem> p = inspectionItemsMapper.findPage(queryPageBean);

        return new PageResult(p.getTotal(),p.getResult());
    }

    @Override
    public void addInspectionItems(CheckItem checkItem) {
        inspectionItemsMapper.add(checkItem);
    }

    @Override
    public void deleteInspectionItems(Integer id) {
        inspectionItemsMapper.deleteById(id);
    }

    @Override
    public void editInspectionItems(CheckItem checkItem) {
        inspectionItemsMapper.update(checkItem);
    }

    @Override
    public CheckItem findById(Integer id) {
        return inspectionItemsMapper.findById(id);
    }

    @Override
    public List<Integer> findCheckItemIdsByCheckGroupId(Integer checkgroupId) {
        return inspectionItemsMapper.findCheckItemIdsByCheckGroupId(checkgroupId);
    }
}
